<template>
	<view class="content" :class="userInfo && userInfo.status!=1?'content_err':''">

		<view class="top_nav">

			<image src="/static/showcase/z619.png" class="imgs" mode=""></image>

			<view class="tex display-flex" @click="$go('weigui')">
				<image src="/static/images/yc.png" class="img1" mode=""></image>
				<text>异常记录</text>
				<image src="/static/images/yc-arrow.png" class="img2" mode=""></image>
			</view>

		</view>
		<view class="navs" >
			<text v-if="userInfo.status==1">
				您的帐号当前处于安全状态
			</text>
			<text v-else>
				您的帐号当前处于异常状态，请立即查看
			</text>
		</view>
		
		<view class="baibox">

			<view class="baili" @click="$go('/showcase/login/phone')">
				<view class="txt">
					绑定手机号
				</view>
				<view class="cenbox">
					<view class="centxt">
						{{userInfo.mobile}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili" @click="$go('/showcase/login/resetting')">
				<view class="txt">
					密码变更
				</view>
				<view class="cenbox">
					<view class="centxt">
						去更改
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			
			<view class="baili" @click="wx_bangd()">
				<view class="txt" >
					绑定微信
				</view>
				<view class="cenbox">
					<view class="centxt">
						{{userInfo.wx_app_nickname?userInfo.wx_app_nickname:"未绑定"}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili">
				<view class="txt">
					dream号
				</view>
				<view class="cenbox">
					<view class="centxt">
						{{userInfo.dream_id}}
					</view>
				</view>
				<!-- <image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image> -->
			</view>
			
			<view class="baili" @click="qqLogin()">
				<view class="txt">
					绑定QQ
				</view>
				<view class="cenbox">
					<view class="centxt">
						{{userInfo.qq_nickname?userInfo.qq_nickname:"未绑定"}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			
			
			<view class="baili" v-if="is_ios" @click="appleLogin()">
				<view class="txt">
					Apple ID
				</view>
				<view class="cenbox">
					<view class="centxt">
				
						{{userInfo.apple_nickname?userInfo.apple_nickname:"未绑定"}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			
			<view class="baili" @click="$go('weigui')">
				<view class="txt">
					违规记录
				</view>
			
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
		<!-- 	
			<view class="baili">
				<view class="txt">
					复议记录
				</view>
				<view class="cenbox">
					<view class="centxt">
						{{userInfo.dream_id}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view> -->
			
			<view class="baili">
				<view class="txt">
					注销帐号
				</view>
				<view class="cenbox" @click="sumb()">
					<view class="centxt reds">
						开始执行
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

		</view>
		<!-- 头像弹框 -->
		<!-- <u-popup :show="show" @close="close" @open="open">
			<view class="mask">
				<view class="manei">
					<view class="matop" >
						<image src="../../static/images/paib.png" class="mapic" mode=""></image>
						<view class="matxt" >
							从相册中选择
						</view>
						<image src="../../static/images/rarr.png" class="mapic" mode=""></image>
					</view>
					<view class="matop" >
						<image src="../../static/images/paia.png" class="mapic" mode=""></image>
						<view class="matxt">
							拍照
						</view>
						<image src="../../static/images/rarr.png" class="mapic" mode=""></image>
					</view>
				</view>
				
				<view class="qubox" @click="show = false">
					取消
				</view>
			</view>
		</u-popup> -->
		
		
		<!-- 注销须知 -->
		<u-popup :show="show1" mode="center" @close="close" @open="open">
			<view class="biaoqian">
				<view class="top">
					<view class="top_username">注销须知</view>
					<view class="createbtn">此操作不可逆</view>
				</view>
				<view class="tab">
					提交的注销申请生效前，dream约文团队将进行以下验证，以保证你的账号、财产安全：
				</view>
				<scroll-view scroll-y="true" class="scroll">
					<view class="">
						1.账号处于安全状态。没有被盗、违规、封禁等风险。
					</view>
					
					<view class="">
						2.dream约文资产已结清，交易已完成。您的所有dream约文资产，包括但不限于粮币、佣金等均已结清、清空。所有交易已经完成。
					</view>
					<view class="">
						3.账号无任何纠纷。包括但不限于举报、申诉、复议，服务均已完成或已自愿放弃。
					</view>
					<view class="">
						4.账号没有签约团队、未绑定团队管理员。
					</view>
					<view class="">
						5.已解除与第三方账号的绑定关系。如手机号、微信等。6.账号无发票正在开具中。
					</view>
					<view class="">
						6.账号无发票正在开具中。
					</view>
					<view class="line">
					</view>
					<view class="white_mask" @click="show1=false,$go('/showcase/user/clear_user')">
						<view>
							我已确认，开始注销
						</view>
					</view>
					
				</scroll-view>
				<image class="cl1" @click="show1=false" :src="'/images/cl1.png' | formatImgUrl" mode=""></image>
			</view>
		</u-popup>
		
		
		<!-- 注销须知 -->
		<u-popup :show="show2" mode="center" @close="close" @open="open">
			<view class="biaoqian">
				<view class="top">
					<view class="top_username">无法开始注销账号</view>
					<view class="createbtn">请确保完成以下内容</view>
				</view>
				
				<scroll-view scroll-y="true" class="scroll">
					<view class="lists" v-for="(item,index) in err_info" @click="tz(item.type)">
						<view class="tops">
							{{item.title}}
							<image :src="'/images/rarr.png' | formatImgUrl" class="imgs" mode=""></image>
						</view>
						<view class="botm">
								{{item.status}}
						</view>
					</view>
				
				</scroll-view>
				<image class="cl1" @click="show2=false" :src="'/images/cl1.png' | formatImgUrl" mode=""></image>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				is_ios:false,
				show1:false,	
				show2:false,
				userInfo: this.$db.get('userInfo'),
				// 头像弹框
				show: false,
				// 标签
				erList: [],
				// 生日
				date: new Date().toLocaleDateString().replace(/\//g, "-"),
				array: ['请选择', '男', '女'],
				index: 0,
				err_info:[]
			}
		},
		onShow() {
			this.getUserInfo()
		},
		onLoad() {
			console.log(uni.getSystemInfoSync().platform,77777777)
			this.is_ios = (uni.getSystemInfoSync().platform === 'ios')
		},
		methods: {
			appleLogin() {
					
				let _this = this;
				console.log('点击apple登录');
				let parameters = {
					openid:'',
					access_token:'',
					nickName:'',
					avatarUrl:'',
				}
				
			
				uni.login({
				    provider: 'apple',
				    success: function (loginRes) {
							
				        // 登录成功
				        uni.getUserInfo({
				            provider: 'apple',
				            success: function(info) {
								console.log("info",info.userInfo)
								//openId
								//fullName  familyName giveName
								if(info.userInfo && info.userInfo.openId){
									console.log(info.userInfo,888888)
									//
									console.log(info.userInfo, 'info');
									_this.$api.default.request(
										'user/bangdappleNickname', {
											info: info.userInfo
										}).then((ret) => {
											console.log(ret,77777777)
											uni.showToast({
												title: "操作成功",
												icon: 'none',
											});
											_this.getUserInfo();
									})
									
									
								}
				                // 获取用户信息成功, info.authResult中保存登录认证数据
				            }
				        })
				    },
				    fail: function (err) {
					
				        // 登录授权失败  
				        // err.code错误码参考`授权失败错误码(code)说明`
				    }
				});
				
				
				
				
			
			
			},
			qqLogin() {
				
			let _this = this;
			console.log('点击qq登录');
			let parameters = {
				openid:'',
				access_token:'',
				nickName:'',
				avatarUrl:'',
			}
			uni.login({
				provider: 'qq',
				success: function(loginRes) {
					console.log(loginRes, 'loginRes');
					parameters.openid = loginRes.authResult.openid
					parameters.access_token = loginRes.authResult.access_token
					// 登录成功
					uni.getUserInfo({
						provider: 'qq',
						success: function(info) {
							// 获取用户信息成功, info.authResult保存用户信息
							//
							console.log(info.userInfo, 'info');
							_this.$api.default.request(
								'user/bangdqqNickname', {
									info: info.userInfo
								}).then((ret) => {
									console.log(ret,77777777)
									uni.showToast({
										title: "操作成功",
										icon: 'none',
									});
									_this.getUserInfo();
							})
						
						}
					})
				},
				fail: function(err) {
					console.log(err, 'qq授权失败');
					// 登录授权失败  
					// err.code是错误码
				}
			});

		},
			wx_bangd(){
				let _this = this;
				console.log("开始登陆--app")
				uni.login({
					"provider": "weixin",
					success: (loginRes) => {
						uni.getUserInfo({
							  provider: 'weixin',
							  success: function (infoRes) {
								  console.log(infoRes,7777777)
								  loginRes.authResult.nickname = infoRes.userInfo.nickName;
									_this.$api.default.request(
										'user/bangdNickname', {
											info: loginRes.authResult
										}).then((ret) => {
											console.log(ret,77777777)
											uni.showToast({
												title: "操作成功",
												icon: 'none',
											});
											_this.getUserInfo();
									})
							  }
						});
					}
				});
			},
			tz(type){
				let url = "";
				
				
				
				switch(type){
					case "1"://查看冻结
						return this.$common.errorToShow("帐号存在冻结")
					break;
					case "2"://查看订单
						url = "/pages/user/order?type=2";
					break;
					case "3"://查看订单
						url = "/pages/user/order?type=2";
					break;
					case "4"://院队
						return this.$common.errorToShow("账户在团状态不支持账号注销")
					break;
					case "5"://发票
						url = "/showcase/showcase/invoice";
					break;
				}
				console.log(type,url,777);
				
				uni.navigateTo({
					url: url
				})
			},
			sumb(){
				let that = this;
				this.$api.default.request('user/checkUser').then((res) => {
					if (res.code) {
						if(res.flag == 0){
							that.show2 = true;
							that.err_info = res.data
						}else{
							that.show1 = true;
						}
					} else {
					}
				})
			},
			close() {
			
			},
			// 开启须知弹窗
			open() {
			
			},
			go_auth() {
				if (this.userInfo.is_auth == 1) {
					uni.navigateTo({
						url: '/pages/user/auth1'
					})
				} else {
					uni.navigateTo({
						url: '/pages/user/auth'
					})
				}

			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
				this.saveUser({
					'sex': this.index
				})
			},
			getUserInfo() {
				
				let that = this;
				this.$api.default.request('user/myuserInfo').then((res) => {
					if (res.code) {
						that.userInfo = res.user
						if(that.userInfo.status!=1){
								uni.setNavigationBarColor({
							     frontColor: '#ffffff',   //字体颜色
							     backgroundColor: '#ED3232'    //背景颜色
							   })
						}
						
						that.index = res.user.sex ? res.user.sex : 0
					} else {
						that.$common.errorToShow(res.msg)
					}
				})
			},
			onChooseAvatar(e) {
				this.$common.uploadImg(e.detail.avatarUrl, (data) => {
					if (data) {
						this.saveUser({
							'pic': data
						})
					}
				})
			},
			bindNick(e) {
				console.log(e)
				if (e.detail.value != this.userInfo.username) {
					this.userInfo.username = e.detail.value
					this.saveUser({
						'username': this.userInfo.username
					})
				}
			},
			saveUser(data) {
				this.$api.default.request('user/saveUser', data).then((res) => {
					if (res.code == 1) {
						this.userInfo = res.user
						this.$common.successToShow(res.msg)
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			// 头像弹框
			open() {

			},
			close() {
				this.show = false
			},
			// 生日
			bindDateChange: function(e) {
				this.date = e.detail.value
				this.saveUser({
					'birthday': e.detail.value
				})
			},
		}
	}
</script>

<style lang="scss">
	.tex{
		position: absolute;
		right: 0;
		top: 25px;
		width: 102px;
		height: 21px;
		background: rgba(255, 255, 255, 0.2);
		justify-content: center;
		border-radius: 15px 0 0 15px;
		font-family: 思源黑体;
		font-size: 12px;
		color: #FFFFFF;
		
		.img1{
			width: 13px;
			height: 13px;
		}
		
		.img2{
			width: 12px;
			height: 12px;
		}
		
		text{
			margin: 0 5rpx;
		}
	}
	
	page {
		background: rgba(242, 245, 242, 1);
	}
	.content_err{
		background: url(/static/showcase/red.png) no-repeat !important;
	}

	.content {
		background: url(/static/showcase/green.png) no-repeat;
		background-size: 100% !important;
		height: 80vh;
		padding-top: 20rpx;

		.top_nav {
			width: 100%;
			text-align: center;

			.imgs {
				width: 550rpx;
				height: 450rpx;
			}

		}
		.navs {
				position: relative;
				top: -195rpx;
				width: 100%;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
		}
			
			
		.baibox {
			width: 84%;
			margin-left: 3%;
			background-color: #ffffff;
			padding: 0 5%;
			margin-bottom: 20rpx;
			border-radius: .5em;
			margin-top: -180rpx;

			.baili:last-child {
				border: none;
			}

			

			.baili {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 120rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.txt {
					width: 40%;
					flex-grow: 1;
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					flex-shrink: 0;
				}

				.cenbox {
					width: 30%;
					flex-grow: 1;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					padding: 0 16rpx;
					.reds{
						color: #ED3232 !important;
					}

					.headpic {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
					}
					.centxt {
						font-size: 28rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						color: #999999;
						width: 440rpx;
					}
					

					.is_auth {
						color: #45C4B0;
					}

					.is_no_auth {
						color: #999;
					}

					.qianbox {
						text-align: right;
						width: 450rpx;
						white-space: nowrap;

						.qli {
							background: rgba(153, 153, 153, 0.1);
							padding: 3rpx 12rpx 4rpx 8rpx;
							border-radius: 178px;
							font-size: 24rpx;
							color: #3D3D3D;
							display: inline-block;
						}

						.qli:not(:first-child) {
							margin-left: 16rpx;
						}
					}
				}

				.rarr {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}
			}
		}

		.mask {
			background: #F2F5F2;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			overflow: hidden;
			.manei {
				margin-bottom: 20rpx;
				background-color: #ffffff;

				.matop {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 40rpx 50rpx;
					border-bottom: 1px solid rgba(153, 153, 153, 0.1);

					.mapic {
						width: 40rpx;
						height: 40rpx;
						flex-shrink: 0;
					}

					.matxt {
						flex-grow: 1;
						font-size: 28rpx;
						padding: 0 16rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}
			}

			.qubox {
				line-height: 120rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
				height: 120rpx;
				opacity: 1;
				background: #FFFFFF;
			}
		}
		
		.biaoqian {
		
			border-radius: 0.5em;
			background: #fff;
			width: 550rpx;
			margin: 0 auto;
			
		
			.top {
				padding-top: 50rpx;
				font-size: 28rpx;
				color: #000;
				text-align: center;
				width: 80%;
				margin-left: 10%;
		
				image {
					width: 130rpx;
					height: 130rpx;
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					top: -35px;
					margin: 0 auto;
					border-radius: 20em;
				}
		
				.top_username {
					font-weight: 700;
					font-size: 30rpx;
					color: #3D3D3D;
				}
		
				view {
					&:last-child {
						margin-top: 6rpx;
						font-family: '思源黑体';
						font-size: 23rpx;
						color: #ED3232;
					}
				}
			}
		
			.tab {
				padding-top: 10rpx;
				font-size: 21rpx;
				font-weight: 700;
				width: 90%;
				margin-left: 5%;
				float: left;
				text-align: left;
				font-family: '思源黑体';
				font-weight: 700;
				font-size: 24rpx;
				margin-top: 10rpx;
				margin-bottom: 8rpx;
				
			}
		
			.scroll {
				padding: 30rpx;
				max-height: 650rpx;
				padding-bottom: 40rpx;
				box-sizing: border-box;
				font-family: '思源黑体';
				font-size: 22rpx;
				color: #3d3d3d;
				position: relative;
				overflow: hidden;
				view{
					margin-bottom: 20rpx;
				}
				.lists{
					float:left;
					width: 100%;
					background:rgba(237, 50, 50, 0.15);
					border-radius: 8px;
					.tops{
						width: 90%;
						margin-left: 5%;
						float:left;
						font-weight: 700;
						font-size: 24rpx;
						margin-bottom: 10rpx !important;
						padding-top: 20rpx;
						.imgs{
							width: 30rpx;
							height: 30rpx;
							float: right;
						}
					}
					.botm{
						margin-left: 5%;
						width: 90%;
						float:left;
						color: #999;
					}
				
				}
			}
			.line{
				height: 1rpx;
				width: 100%;
				background: rgba(153, 153, 153, 0.1);
				margin-top:40rpx;
		
			}
			.white_mask{
				position: sticky;
				padding-bottom: 10px;
				bottom: -50px;
				left: 0;
				width: 100%;
				height: 80rpx;
				
				background: linear-gradient(to bottom, rgba(255,255,255, 0),rgba(255,255,255, .8));
				view{
					width: 90%;
					height: 80rpx;
					line-height: 80rpx;
					color: #fff;
					text-align: center;
					border-radius: 0.5em;
					background: #ED3232;
					margin: 0 auto;
				}
			}
		}
		.cl1 {
			height: 40rpx;
			width: 40rpx;
			position: absolute;
			margin-top:40rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>